{include file="public/public"}
<style>
	.modify_email {
		color: #EFA538;
	}
	
	.modify_email:link {
		color: #EFA538;
	}
	
	.modify_email:visited {
		color: #EFA538;
	}
	
	.modify_email:hover {
		color: #1987E7;
	}
	
	.modify_email:active {
		color: #EFA538;
	}
	
	.editname,
	.editaddr {
		cursor: pointer;
		text-decoration: underline;
	}
</style>
<script src="__PUBLIC__/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
	function deleteAll() {
		var arr = "";
		$("input[name=contentbox]:checked").each(function() {
			arr += $(this).val() + ",";
		})
		if(arr == "") {
			alert('请选择要删除的信息');
			return false;
		}
		if(!confirm("您确定要删除吗？")) {
			return false;
		}
		$.post("__APP__/admin/deleteAllEmail", {
			arr: arr
		}, function(data) {
			if(data.result) {
				alert(data.msg);
				location.reload();
			} else {
				alert(data.msg);
			}
		}, "json");
	}


    function sendAll() {
        var arr = "";
        $("input[name=contentbox]:checked").each(function() {
            arr += $(this).attr("email") + ",";
        })
        if(arr == "") {
            alert('请选择要发送的人员');
            return false;
        }
        $.post("__APP__/email/sendAllEmail", {
            arr: arr
        }, function(data) {
            if(data.result) {
                alert(data.msg);
                location.reload();
            } else {
                alert(data.msg);
            }
        }, "json");
    }



    function checkallstu(o) {
		if(o.checked) {
			$("input[name='contentbox']").attr("checked", true);
		} else {
			$("input[name='contentbox']").attr("checked", false);
		}
	}

	function preAdd() {
		$('#main_email').show();
		$('#addBtn').hide();
	}

	function addList() {
		var name = $('#ename').val();
		var address = $('#eaddress').val();
		var subjectType = $("#esubType").val();
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!name) {
			alert('名字不能为空~');
			return false;
		}
		if(!address || !filter.test(address)) {
			alert('邮箱格式不正确~');
			return false;
		}
		$.post("__APP__/admin/addEmailList", {
			name: name,
			address: address,
			subjectType: subjectType
		}, function(data) {
			if(data.result) {
				alert(data.msg);
				location.reload();
			} else {
				alert(data.msg);
			}
		}, "json");
	}

	function cancelList() {
		$('#main_email').hide();
		$('#addBtn').show();
	}

	function subsou() {
		var souname = $("#souname").val();
		window.location.href = '__APP__/admin/emailManage?soname=' + souname;
	}
	$(function() {
		$('#eaddress').bind('keypress', function(event) {
			if(event.keyCode == "13") {
				addList();
			}
		});
	});
</script>
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
	<div class="layui-body layui-tab-content site-demo site-demo-body">
		<div class="layui-tab-item layui-show">
			<div class="layui-main">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;"></fieldset>
				<span class="layui-breadcrumb">
                    <a href="__APP__/{$menuConfigArry['functionMod']}/{$menuConfigArry['menuLabel']}">{$menuConfigArry['pmenuName']}</a>
                    <a><cite>{$menuConfigArry['menuName']}</cite></a>
                </span>
				<hr>
				<div class="layui-form-item" style="margin-top: 20px;">
					<div class="layui-inline">
						<!--<div class="content_3_fdj"><img src="__PUBLIC__/images/fdj.jpg" /></div>-->
						<label class="layui-form-label">联系人：</label>
						<div class="layui-input-inline">
							<input id='souname' name="text2" type="text" class="layui-input" />
						</div>
						<a href="#" onClick="subsou()" class="layui-btn ">查询</a>
					</div>
				</div>
				<table class="layui-table" lay-skin="line">
					<thead>
						<tr>
							<td width="51">选择</td>
							<td width="70">id</td>
							<td width="110">联系人</td>
							<td width="57">邮箱地址</td>
							<td width="87">主题</td>
							<td width="87">备注</td>
							<!--<td width="49" >操作</td>-->
						</tr>
					</thead>
					<tbody>
						<?
					      	if($contents){
					      		foreach($contents as $val){
					      	 		$tmp = addslashes(json_encode($val));
					     	// $stime=date("Y-m-d H:i",$val['stime']);
					
					   ?>
							<tr class="ctt_white">
								<td><input type="checkbox" name="contentbox" id="contentbox" value="{$val[id]}" email="{$val[address]}"></td>
								<td>{$val[id]}</td>
								<td class='editname' eid={$val[id]}>{$val[name]}</td>
								<td class='editaddr' eid={$val[id]}>{$val[address]}</td>
								<td>{$val[subject]}</td>
								<td>{$val[info]}</td>
							</tr>
							<?php
						 	}
					  }?>
					</tbody>
				</table>
				<div class="content_1234">
					<div class="content_glcz">管理操作：全选
						<input name="checkbox" type="checkbox" onClick="checkallstu(this)" />
						<input name="submit" type="button" value="删除" onclick="deleteAll()" class="layui-btn layui-btn-sm layui-btn-warm" />
						<!--  附件地址:<input id='attach'  name="eattach" type="text" size=15/>-->
            	<input name="submit" type="button" value="发送邮件"  class="layui-btn layui-btn-sm layui-btn-warm"  onclick="sendAll()"  class="btn_01"/>

					</div>
					<div class="content_glcz">
						<input name="submit" id='addBtn' type="button" value="添加信息" onclick="preAdd()" class="layui-btn layui-btn-sm" />
						<span id='main_email' style='display:none;'>
            	联系人:<input id='ename'  name="emaillist" type="text"  size=6/>
            	邮箱地址:<input id='eaddress' name="emaillist" type="text" keydown="econfirm()" size=15/>
            	<input name="submit" id='doAdd' type="button" value="确认添加" onclick="addList()"  class="layui-btn layui-btn-sm"/>
            	<input name="quxiao" id='docancel' type="button" value="取消" onclick="cancelList()"  class="layui-btn layui-btn-sm layui-btn-warm"/>
            	</span>
					</div>
					<div class="layui-box layui-laypage layui-laypage-default">{$page}</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/bootstrap/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/bootstrap3-editable-1.5.1/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<script>
	$(function() {
		$('.editname').editable({
			type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
			title: "默认值", //编辑框的标题
			disabled: false, //是否禁用编辑
			emptytext: "未设置", //空值的默认文本
			mode: "inline", //编辑框的模式：支持popup和inline两种模式，默认是popup
			validate: function(value) { //字段验证
				if(!value) {
					alert('名字不能为空~');
					return false;
				}
				var id = $(this).attr('eid');
				$.post('__APP__/admin/modifyEmail', {
					'id': id,
					'name': value,
					'type': 'name'
				}, function(data) {
					if(!data.result) {
						alert(data.msg);
						window.location.reload();
					}
				}, 'json');

			}
		});
		$('.editaddr').editable({
			type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
			title: "默认值", //编辑框的标题
			disabled: false, //是否禁用编辑
			emptytext: "未设置", //空值的默认文本
			mode: "inline", //编辑框的模式：支持popup和inline两种模式，默认是popup
			validate: function(value) { //字段验证
				var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if(!value || !filter.test(value)) {
					alert('邮箱格式不正确~');
					return false;
				}
				var id = $(this).attr('eid');
				$.post('__APP__/admin/modifyEmail', {
					'id': id,
					'address': value,
					'type': 'address'
				}, function(data) {
					if(!data.result) {
						alert(data.msg);
						window.location.reload();
					}
				}, 'json');
			}
		});
	});
</script>